package com.zgm.ch05.aop.around._3_5_5;

import java.lang.reflect.Method;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.util.StopWatch;

public class ProfilingInterceptor implements MethodInterceptor {

	public Object invoke(MethodInvocation invocation) throws Throwable {
		
		StopWatch sw = new StopWatch();
		sw.start(invocation.getMethod().getName());
		Object returnValue = invocation.proceed();
		sw.stop();
		dumpInfo(invocation, sw.getTotalTimeMillis());
//		return returnValue;
		return 2;
	}
	
	
	private void dumpInfo(MethodInvocation invocation, long ms) {
		Method m = invocation.getMethod();
		Object target = invocation.getThis();
		Object[] args = invocation.getArguments();
		
		System.out.println("执行方法：" + m.getName());
		
		for (int i = 0; i < args.length; i++) {
			System.out.println("传进方法的实际参数是：" + args[i]);
		}
		
		System.out.println("");
		
		System.out.println("发费： " + ms + " ms");
	}
	

}
